package Collert

import (
	"github.com/gin-gonic/gin"
	"models"
	"net/http"
	"strconv"
	"types"
)

// 添加秒杀商品
func ShopAdd(c *gin.Context) {
	ShopName := c.PostForm("shop_name")
	ShopPrice, _ := strconv.Atoi(c.PostForm("shop_price"))
	ShopNum, _ := strconv.Atoi(c.PostForm("shop_num"))
	ShopStu, _ := strconv.Atoi(c.PostForm("shop_stu"))
	pone := models.Shop{
		ShopName:  ShopName,
		ShopPrice: float64(ShopPrice),
		ShopNum:   ShopNum,
		ShopStu:   ShopStu,
	}
	err := pone.ShopAdd()
	if err != nil {
		c.JSON(http.StatusBadRequest, types.Router{
			Code:     -1,
			Msg:      "秒杀商品添加失败",
			Database: nil,
		})
		return
	}

	c.JSON(http.StatusOK, types.Router{
		Code:     200,
		Msg:      "秒杀成功",
		Database: nil,
	})
}

// 秒杀商品列表
func ShopList(c *gin.Context) {
	pone := models.Shop{}
	res, err := pone.ShopList()
	if err != nil {
		c.JSON(http.StatusBadRequest, types.Router{
			Code:     -1,
			Msg:      "展示失败",
			Database: nil,
		})
		return
	}
	c.JSON(http.StatusOK, types.Router{
		Code:     200,
		Msg:      "秒杀商品",
		Database: res,
	})
}
